package com.sl.hiweigowebapp;

/**
 * Created with IDEA
 * author:ShiLiang
 * Date:2019/5/31
 * Time:0:29
 */
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Controller
class MainsiteErrorController implements ErrorController {
    @RequestMapping("/error")
    public String handleError(HttpServletRequest request, HttpServletResponse response){
        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
        if(statusCode == 401){
            return "/401";
        }else if(statusCode == 404){
            response.setStatus(200);
            return "/index";
        }else if(statusCode == 403){
            return "/403";
        }else{
            return "/500";
        }
    }
    @Override
    public String getErrorPath() {
        return "/error";
    }
}